package com.ljh.gateway;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author: Themberfue
 * @date: 2025/4/22 14:19
 * @description:
 */
@Slf4j
@Component
public class CustomGlobalFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        // TODO 1. Pre 请求
        log.info("Pre Global Filter...");

        // TODO 2. 执行请求
        return chain.filter(exchange)

                // TODO 3. Post 类型
                .then(Mono.fromRunnable(() -> {
                    log.info("Post Global Filter...");
                }));
    }

    @Override
    public int getOrder() {
        return Ordered.LOWEST_PRECEDENCE;
    }
}
